// alipay.service.js
const AlipaySdK = require('alipay-sdk').default;
const AlipaySdkForm = require('alipay-sdk/lib/form').default;
const alipayConfig = require('./alipay.config');
// 创建支付宝客户端实例
const alipaySdk = new AlipaySdK({
    appId: alipayConfig.appId,
    gateway: alipayConfig.gateway,
    privateKey: alipayConfig.privateKey,
    alipayPublicKey: alipayConfig.alipayPublicKey,
    signType: alipayConfig.signType
});
// 执行支付宝支付请求
const createAlipayPagePay = async (orderData) => {
    let formData = new AlipaySdkForm();
    formData.addField('returnUrl', 'http://localhost:8000/ordepage');
    formData.addField('bizContent', {
        outTradeNo: Date.now(),
        productCode: 'FAST_INSTANT_TRADE_PAY',
        totalAmount: orderData.totalAmount,
        subject: orderData.subject,
        body: orderData.body
    });
    const result = await alipaySdk.exec(
        'alipay.trade.wap.pay',//支付类型  wap.pay-H5端支付  page.pay-PC端支付
        {},
        { formData: formData }
    );
    return result;
};
module.exports = {
    createAlipayPagePay
};